﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using 开单.Dao.基础;
using 开单.Model.基础;
using 开单.DB;

namespace 开单
{
    public partial class FrmLogin : Form
    {
        YhxxEntity yhxxEntity = new YhxxEntity();
        YhxxDao yhxxDao = new YhxxDao();
        public FrmLogin()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(!(IsOkToLogin())){return;}
            yhxxEntity= yhxxDao.GetYhxxToLogin(TxtYhName.Text, TxtYhPsw.Text);
            if (yhxxEntity == null)
            {
                MessageBox.Show("账号或密码错误");
                return;
            }
            else
            {
                if (yhxxEntity.yh_kybz != "是") { MessageBox.Show("该账号已经被禁用！"); return; }
                if (yhxxEntity.yh_name == "温州仲雄")
                {
                    GlobalVar.yhxxEntity = yhxxEntity;
                    FrmMain frm = new FrmMain();
                    GlobalVar.frmMain = frm;
                    GlobalVar.frmLogin = this;
                    frm.Show();
                    this.Hide();
                }
                else if (yhxxEntity.yh_name == "zhongxiong")
                {
                    GlobalVar.yhxxEntity = yhxxEntity;
                    FrmMain frm = new FrmMain();
                    GlobalVar.frmMain = frm;
                    GlobalVar.frmLogin = this;
                    frm.button5.Visible = false;
                    frm.button6.Visible = false;
                    frm.Show();
                    this.Hide();
                }
                else
                {
                    GlobalVar.yhxxEntity = yhxxEntity;
                    FrmMain frm = new FrmMain();
                    GlobalVar.frmMain = frm;
                    GlobalVar.frmLogin = this;
                    frm.button2.Visible = false;
                    frm.button3.Visible = false;
                    frm.button4.Visible = false;
                    frm.button5.Visible = false;
                    frm.button6.Visible = false;
                    frm.Show();
                    this.Hide();
                }
            }
        }

        private bool IsOkToLogin()
        {
            if (TxtYhName.Text.Trim() == "") { MessageBox.Show("请输入账号"); return false; }
            if (TxtYhPsw.Text.Trim() == "") { MessageBox.Show("请输入密码"); return false; }
            return true;
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
